package com.woniuxy.portal.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.portal.client.UserApi;
import com.woniuxy.user.dto.AddUserDto;
import com.woniuxy.user.entity.SystemUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags="远程调用控制器")
@RequestMapping
public class PortalController {
    @Autowired
    private UserApi userApi;

    @GetMapping("/feign")
    @ApiOperation("远程调用查询手机号")
    public SystemUser getSystemUser(String userPhone) {
        SystemUser user = userApi.getUser(userPhone);
        return user;
    }

    @PostMapping("/batDelete")
    @ApiOperation("批量删除")
    public ResponseEntity<String> batDelete(@RequestBody List<Integer> ids){
        ResponseEntity<String> entity = userApi.batchDelete(ids);
        return entity;
    }

    @PostMapping("/getAllUserBySex")
    @ApiOperation("根据性别查询分页")
    public Page<SystemUser> getByUserSex(Integer userSex, Integer pageNum, Integer pageSize){
        Page<SystemUser> byUserSex = userApi.getByUserSex(userSex, pageNum, pageSize);
        return byUserSex;
    }
    @PostMapping("/saveUser")
    @ApiOperation("远程添加用户")
    public ResponseEntity addUser(@RequestBody AddUserDto addUserDto){
        ResponseEntity user = userApi.addUser(addUserDto);
        return ResponseEntity.ok(user);
    }
    @GetMapping("/getAllUserByName")
    @ApiOperation("远程姓名查询用户")
    public Page<SystemUser> getByUserName(@RequestParam("userName") String userName,
                                   @RequestParam("pageNum") Integer pageNum,
                                   @RequestParam("pageSize") Integer pageSize){
        Page<SystemUser> userPage = userApi.getByUserName(userName, pageNum, pageSize);
        return userPage;
    }
}
